﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ATMS.Repository
{
    /// <summary>
    /// This is an example of extending the IRepository<![CDATA[<USER>]]>
    /// 
    /// If the link table just contains the two fields, EF handles the magic on its own.
    /// However, if the link table contains more than the two FK fields, EF will create a separate entity for it
    /// 
    /// See how Entity Framework handles link tables: http://smehrozalam.wordpress.com/2010/06/29/entity-framework-queries-involving-many-to-many-relationship-tables/
    /// </summary>
    public static class UserRepository
    {
        /// <summary>
        /// Return user names in a given group
        /// </summary>
        /// <param name="userRepository"></param>
        /// <param name="groupId"></param>
        /// <returns></returns>
        public static IEnumerable<char> GetUsersByGroup(this IRepository<ATMS.DAL.USERGROUP> userRepository, string groupId)
        {
            var userList = userRepository
                .FindById(groupId)
                .USERS.SelectMany(u => u.USERNAME);
                
            return userList;
        }
    }
}
